home *** CD-ROM | disk | FTP | other *** search
- property pBarSpots, pNumberSpots, pCharList, pPurgatoryList, pMaxInPurgatory, pPukatoryList, pMaxInPukatory, pArbusExileList, pActiveSlot, pGlassMask, pGlassIce, pGlassCheat
- global gGameLevel, gBarGlassSprites
-
- on new me
- global gImplementedCharacters, gDemoVersion
- pCharList = []
- repeat with Y = 1 to count(gImplementedCharacters)
- add(pCharList, getPropAt(gImplementedCharacters, Y))
- end repeat
- pPurgatoryList = []
- pPukatoryList = []
- pArbusExileList = []
- if gDemoVersion then
- pMaxInPurgatory = 1
- pMaxInPukatory = 1
- else
- pMaxInPurgatory = 3
- pMaxInPukatory = 2
- end if
- pBarSpots = []
- pBarSprites = gBarGlassSprites
- pNumberSpots = count(pBarSprites)
- repeat with X = 1 to pNumberSpots
- add(pBarSpots, [#charCode: #none, #glassType: #none, #glassMemberName: EMPTY, #xCoord: 130 + ((X - 1) * 180), #sprite: pBarSprites[X], #posOffset: 0])
- end repeat
- pGlassMask = 1
- pGlassCheat = 2
- pGlassIce = -1
- return me
- end
-
- on mInitialize
- end
-
- on mGetNumBarSlots
- return pNumberSpots
- end
-
- on getClosestOpenSpot me, xLoc
- barSlot = 0
- proximity = the maxinteger
- repeat with X = 1 to count(pBarSpots)
- if not barSpotIsFree(me, X) then
- thisSpot = pBarSpots[X]
- if abs(xLoc - thisSpot[#xCoord]) < proximity then
- proximity = abs(xLoc - thisSpot[#xCoord])
- barSlot = X
- end if
- end if
- end repeat
- if getBarTopGlass(me, barSlot) = #none then
- return [#closest: barSlot, #open: 1]
- else
- return [#closest: barSlot, #open: 0]
- end if
- end
-
- on barSpotAllowed me, barSlot
- global gImplementedCharacters
- barSlotOK = 1
- repeat with X = 1 to count(pBarSpots)
- if barSpotIsFree(me, X) then
- next repeat
- end if
- checkAgainst = pBarSpots[X][#charCode]
- if voidp(checkAgainst) then
- debugAlert("VERY wrong checkAgainst value" && checkAgainst && X && count(gImplementedCharacters))
- next repeat
- else
- extantCharInfo = gImplementedCharacters[checkAgainst]
- if voidp(extantCharInfo) then
- debugAlert("VERY wrong extantCharInfo or checkAgainst" && checkAgainst && X && count(gImplementedCharacters))
- next repeat
- end if
- end if
- case X of
- 1:
- barSlotOK = spotIsOkay(me, extantCharInfo, barSlot, #P1F)
- 2:
- barSlotOK = spotIsOkay(me, extantCharInfo, barSlot, #P2F)
- 3:
- barSlotOK = spotIsOkay(me, extantCharInfo, barSlot, #P3F)
- end case
- if not barSlotOK then
- exit repeat
- end if
- end repeat
- return barSlotOK
- end
-
- on spotIsOkay me, charToCheck, disallowMe, excludesThese
- repeat with X in charToCheck[excludesThese]
- if X = disallowMe then
- return 0
- end if
- end repeat
- return 1
- end
-
- on getOpenBarSeat me
- global gGameLevel
- openBarSeats = []
- repeat with X = 1 to count(pBarSpots)
- if barSpotIsFree(me, X) then
- if barSpotAllowed(me, X) or inTestMode() then
- add(openBarSeats, X)
- end if
- end if
- end repeat
- if count(openBarSeats) = 0 then
- return 0
- else
- if gGameLevel > 1 then
- if count(openBarSeats) = 3 then
- return 2
- else
- if count(openBarSeats) = 2 then
- if (openBarSeats[1] = 1) and (openBarSeats[2] = 2) then
- return 1
- else
- if (openBarSeats[1] = 2) and (openBarSeats[2] = 3) then
- return 3
- else
- return randomFromList(openBarSeats)
- end if
- end if
- else
- return randomFromList(openBarSeats)
- end if
- end if
- else
- return randomFromList(openBarSeats)
- end if
- end if
- end
-
- on setActiveSlot me, newSlot, nextOne
- if nextOne then
- newSlot = findNExtOccupiedSlot(me)
- end if
- if newSlot = 0 then
- newSlot = findNExtOccupiedSlot(me)
- else
- if barSpotIsFree(me, newSlot) then
- alertBeep()
- exit
- end if
- end if
- if newSlot then
- if pActiveSlot <> newSlot then
- pActiveSlot = newSlot
- refreshRecipes(pActiveSlot)
- end if
- end if
- updateLaserPointer()
- end
-
- on findNExtOccupiedSlot me, startingAt
- global debug
- if voidp(startingAt) then
- startingAt = getActiveSlot(me)
- end if
- startingAt = startingAt + 1
- if startingAt > 3 then
- startingAt = 1
- end if
- if debug then
- put "Finding next occupied slot starting at" && startingAt
- end if
- repeat with X = startingAt to count(pBarSpots)
- if not barSpotIsFree(me, X) then
- return X
- end if
- end repeat
- repeat with X = 1 to startingAt
- if not barSpotIsFree(me, X) then
- return X
- end if
- end repeat
- return 0
- end
-
- on getActiveSlot me
- if voidp(pActiveSlot) or (pActiveSlot = 0) then
- pActiveSlot = findNExtOccupiedSlot(me, 1)
- updateLaserPointer()
- refreshRecipes(pActiveSlot)
- else
- if barSpotIsFree(me, pActiveSlot) then
- pActiveSlot = findNExtOccupiedSlot(me, 1)
- updateLaserPointer()
- refreshRecipes(pActiveSlot)
- end if
- end if
- return pActiveSlot
- end
-
- on getRandomCharacter me, fillThisSeat
- global pForce, gImplementedCharacters, gGameLevel, debug, gCharChildren, gDemoVersion
- if not voidp(pForce) then
- return pForce
- end if
- newCharOK = 0
- noEasierThanCharacter = 1
- charactersRemaining = duplicate(pCharList)
- specialChars = []
- repeat with X = 1 to count(charactersRemaining)
- specialCharInfo = gImplementedCharacters[charactersRemaining[X]]
- if specialCharInfo[#MINLEVEL] > gGameLevel then
- next repeat
- end if
- case fillThisSeat of
- 1:
- if (specialCharInfo[#P1A] <> 0) and count(specialCharInfo[#P1F]) then
- add(specialChars, charactersRemaining[X])
- end if
- 2:
- if (specialCharInfo[#P2A] <> 0) and count(specialCharInfo[#P2F]) then
- add(specialChars, charactersRemaining[X])
- end if
- 3:
- if (specialCharInfo[#P3A] <> 0) and count(specialCharInfo[#P3F]) then
- add(specialChars, charactersRemaining[X])
- end if
- end case
- end repeat
- tixFreq = currentLevel(#TIXINFREQ)
- ticketedChars = []
- if tixFreq > 0 then
- repeat with z = 1 to count(charactersRemaining)
- if gCharChildren[z].pDrinkTicket > 0 then
- add(ticketedChars, getPropAt(gCharChildren, z))
- end if
- end repeat
- end if
- repeat while not newCharOK
- if count(ticketedChars) and (random(tixFreq) = 1) then
- if debug then
- put "Picking a ticketed characters" && ticketedChars
- end if
- thisIndex = random(count(ticketedChars))
- thisOne = ticketedChars[thisIndex]
- else
- if (gGameLevel > 1) and count(specialChars) and (random(4) = 1) then
- thisIndex = random(count(specialChars))
- thisOne = specialChars[thisIndex]
- else
- thisIndex = random(count(charactersRemaining))
- thisOne = charactersRemaining[thisIndex]
- end if
- end if
- chosenCharInfo = gImplementedCharacters[thisOne]
- if count(charactersRemaining) = 1 then
- if numberAtBar(me) > 0 then
- return VOID
- else
- if debug then
- put "Accepted out of desperation" && thisOne
- end if
- return thisOne
- end if
- end if
- newCharOK = 1
- case fillThisSeat of
- 1:
- newCharOK = checkExclusions(me, chosenCharInfo, #P1A, #P1F)
- customPosCheck = #P1A
- 2:
- newCharOK = checkExclusions(me, chosenCharInfo, #P2A, #P2F)
- customPosCheck = #P2A
- 3:
- newCharOK = checkExclusions(me, chosenCharInfo, #P3A, #P3F)
- customPosCheck = #P3A
- end case
- if newCharOK then
- if chosenCharInfo[customPosCheck] = 0 then
- if debug then
- put "This should never happen. We just found out this position is okay. So it shouldn't be zero."
- end if
- newCharOK = 0
- posOffset = 0
- else
- if chosenCharInfo[customPosCheck] = 1 then
- posOffset = 0
- else
- posOffset = chosenCharInfo[customPosCheck]
- end if
- end if
- setBarPositionOffset(me, fillThisSeat, posOffset)
- end if
- if (chosenCharInfo[#MINLEVEL] > gGameLevel) and not inRecipeMode() then
- if not gDemoVersion then
- if debug then
- put "Excluded for gameLevel" && thisOne && gGameLevel && chosenCharInfo[#MINLEVEL]
- end if
- newCharOK = 0
- end if
- end if
- if chosenCharInfo[#MINLEVEL] < noEasierThanCharacter then
- if debug then
- debugAlert("Excluded for too low a gameLevel" && thisOne && gGameLevel && chosenCharInfo[#MINLEVEL])
- end if
- newCharOK = 0
- end if
- repeat with X = 1 to count(pBarSpots)
- if barSpotIsFree(me, X) then
- next repeat
- else
- checkAgainst = pBarSpots[X][#charCode]
- end if
- if checkAgainst = thisOne then
- if debug then
- put "Excluded for duplication" && thisOne
- end if
- newCharOK = 0
- exit repeat
- next repeat
- end if
- if getOne(gImplementedCharacters[checkAgainst][#EXCLUDECHAR], thisOne) then
- if debug then
- put "Excluded for conflict by character" && thisOne && gImplementedCharacters[checkAgainst][#EXCLUDECHAR]
- end if
- newCharOK = 0
- exit repeat
- end if
- end repeat
- if gCharChildren[thisOne].pBouncedPermanently then
- if debug then
- put "Excluded for permanent bouncing" && thisOne
- end if
- newCharOK = 0
- end if
- if getOne(pArbusExileList, thisOne) then
- if debug then
- put "Excluded for bouncing this round (arbusExile)" && thisOne
- end if
- newCharOK = 0
- end if
- if getOne(pPurgatoryList, thisOne) then
- if debug then
- put "Excluded for recent visit (purgatory)" && thisOne
- end if
- newCharOK = 0
- end if
- if getOne(pPukatoryList, thisOne) then
- if debug then
- put "Excluded for pukatory" && thisOne
- end if
- newCharOK = 0
- end if
- if getOne(specialChars, thisOne) > 0 then
- deleteAt(specialChars, getOne(specialChars, thisOne))
- end if
- if getOne(ticketedChars, thisOne) > 0 then
- deleteAt(ticketedChars, getOne(ticketedChars, thisOne))
- end if
- if getOne(charactersRemaining, thisOne) > 0 then
- deleteAt(charactersRemaining, getOne(charactersRemaining, thisOne))
- end if
- if debug then
- put "Rejected all but the last one printed" && thisOne
- end if
- end repeat
- if debug then
- put "New character enters:" && thisOne
- end if
- return thisOne
- end
-
- on checkExclusions me, charToCheck, allowed, excluded
- if charToCheck[allowed] = 0 then
- return 0
- end if
- repeat with X in charToCheck[excluded]
- if not barSpotIsFree(me, X) then
- return 0
- end if
- end repeat
- repeat with X in charToCheck[excluded]
- if not barSpotIsFree(me, X) then
- return 0
- end if
- end repeat
- return 1
- end
-
- on maxAutoAtBar me
- maxAutoPatrons = min(2, currentLevel(#MaxPatrons))
- if numberAtBar(me) >= maxAutoPatrons then
- return 1
- else
- return 0
- end if
- end
-
- on maxAtBar me
- MaxPatrons = currentLevel(#MaxPatrons)
- if inTestMode() then
- MaxPatrons = 3
- end if
- if numberAtBar(me) >= MaxPatrons then
- return 1
- else
- return 0
- end if
- end
-
- on numberAtBar me
- countMe = 0
- repeat with X = 1 to count(pBarSpots)
- if not barSpotIsFree(me, X) then
- countMe = countMe + 1
- end if
- end repeat
- return countMe
- end
-
- on barSpotIsFree me, thisSpot
- return pBarSpots[thisSpot][#charCode] = #none
- end
-
- on addToPukatory me, barSlot
- add(pPukatoryList, pBarSpots[barSlot][#charCode])
- if count(pPukatoryList) > pMaxInPukatory then
- deleteAt(pPukatoryList, 1)
- end if
- end
-
- on setBarTopCharacter me, barSlot, charCode
- if count(pPurgatoryList) > pMaxInPurgatory then
- deleteAt(pPurgatoryList, 1)
- end if
- pBarSpots[barSlot][#charCode] = charCode
- end
-
- on removeBarTopCharacter me, barSlot
- global gLastVessel
- add(pPurgatoryList, pBarSpots[barSlot][#charCode])
- pBarSpots[barSlot][#charCode] = #none
- if count(pPurgatoryList) > pMaxInPurgatory then
- deleteAt(pPurgatoryList, 1)
- end if
- removeBarTopGlass(me, barSlot)
- barGlass = getActiveGlass()
- if barGlass = 0 then
- setPourClockText(" Drink Contents Shown Here")
- gLastVessel = 0
- else
- barGlass.pContentString = EMPTY
- gLastVessel = sprite(barGlass).pMyBarSlot
- newString = buildVesselContentList(barGlass, barGlass.pGlassType, " The Glass is Empty")
- setPourClockText(newString)
- end if
- end
-
- on removeBarTopGlass me, barSlot
- pBarSpots[barSlot][#glassType] = #none
- pBarSpots[barSlot][#glassMemberName] = EMPTY
- sendSprite(barSlotToGlassSprite(me, barSlot), #mRemoveDrink)
- end
-
- on barSlotToGlassSprite me, barSlot
- if (barSlot < 1) or (barSlot > count(pBarSpots)) then
- return VOID
- else
- return sprite(pBarSpots[barSlot][#sprite])
- end if
- end
-
- on setBarPositionOffset me, barSlot, newOffset
- if (barSlot > 0) and (barSlot <= count(pBarSpots)) then
- pBarSpots[barSlot][#posOffset] = newOffset
- end if
- end
-
- on getBarPositionOffset me, barSlot
- if (barSlot < 1) or (barSlot > count(pBarSpots)) then
- return 0
- else
- return pBarSpots[barSlot][#posOffset]
- end if
- end
-
- on getBarTopGlass me, barSlot
- if (barSlot < 1) or (barSlot > count(pBarSpots)) then
- return #none
- else
- return pBarSpots[barSlot][#glassType]
- end if
- end
-
- on getBarTopGlassMember me, barSlot
- if (barSlot < 1) or (barSlot > count(pBarSpots)) then
- return EMPTY
- else
- return pBarSpots[barSlot][#glassMemberName]
- end if
- end
-
- on mDrinkOffset me, barSlot, glassType
- global gImplementedCharacters
- charCode = pBarSpots[barSlot][#charCode]
- if charCode = #none then
- glassPosition = point(0, 0)
- else
- theseGlassXYs = gImplementedCharacters[charCode][#glassXY]
- glassPosition = theseGlassXYs[symbol(glassPrefix(glassType))]
- if voidp(glassPosition) then
- glassPosition = theseGlassXYs[#def]
- end if
- end if
- return point(glassPosition.locH + getBarPositionOffset(me, barSlot), glassPosition.locV)
- end
-
- on setBarTopGlass me, barSlot, newMember, glassType, keepOldMaskAndIce, transferContents, newGarnish, oldIceAmount
- newLoc = point(pBarSpots[barSlot][#xCoord], 251) + mDrinkOffset(me, barSlot, glassType)
- glassSprite = barSlotToGlassSprite(me, barSlot)
- pBarSpots[barSlot][#glassType] = glassType
- pBarSpots[barSlot][#glassMemberName] = newMember
- sendSprite(glassSprite, #mPlaceDrink, newMember, newLoc, glassType, keepOldMaskAndIce)
- sendSprite(glassSprite, #mUpdateContents, glassType, transferContents, newGarnish, oldIceAmount)
- setActiveSlot(me, barSlot)
- end
-
- on showBarGlass me, barSlot, flag
- glassSprite = barSlotToGlassSprite(me, barSlot)
- if flag then
- sendSprite(glassSprite, #mShowDrink)
- else
- sendSprite(glassSprite, #mHideDrink)
- end if
- end
-
- on mOverItem me, bottleSprite, spoutLoc
- repeat with X in pBarSpots
- Y = pBarSpots[#sprite]
- if sendSprite(Y, #mOverItem, bottleSprite, spoutLoc) then
- return 1
- end if
- end repeat
- return 0
- end
-